<template>
  <div class="login-account-form">
    <el-form ref="loginForm" :model="loginForm" :rules="rules">
      <el-form-item prop="loginName" class="user">
        <el-input
          v-model="loginForm.loginName"
          name="loginName"
          placeholder="请输入用户名或者手机号"
          autocomplete="new-password">
          <i slot="prefix" class="iconfont icon-chakanjingjirenzhuye perfix-icon"></i>
        </el-input>
      </el-form-item>
      <el-form-item prop="loginPassword" class="password">
        <el-input
          v-model="loginForm.loginPassword"
          :type="inputStyle"
          name="loginPassword"
          label="密码"
          placeholder="请输入密码"
          @keyup.enter.native="alyOnSubmit"
          @focus="passwordWarning = false"
          autocomplete="new-password">
          <i slot="prefix" class="el-icon-lock perfix-icon"></i>
          <span slot="suffix" class="pwd-eye-view" @click="togglePwdDisplay">
            <i class="iconfont icon-biyan" v-show="inputStyle === 'password'"></i>
            <i class="iconfont icon-zhengyan" v-show="inputStyle === 'text'"></i>
          </span>
        </el-input>
      </el-form-item>
      <div class="options">
        <div class="remember">
          <!-- <el-checkbox v-model="remember">记住密码</el-checkbox> -->
        </div>
        <div class="forget">
          <el-button type="text" @click="$emit('show-forget')">忘记密码？</el-button>
        </div>
      </div>
      <div class="login-btn" @click="alyOnSubmit">登 录</div>
    </el-form>
  </div>
</template>
<script>
export default {
  name: 'AccountForm',
  emits: ['login', 'show-dialog'],
  data() {
    return {
      loginForm: {
        loginName: '',
        smCode: '',
        loginPassword: '',
      },
      rules: {
        loginName: [{ required: true, message: '请填写用户名', trigger: 'blur' }],
        loginPassword: [{ required: true, message: '请填写密码', trigger: 'blur' }],
      },
      remember: false,
      inputStyle: 'text',
    }
  },
  mounted() {
    this.logInfo()
    this.$nextTick(() => {
      setTimeout(() => {
        this.inputStyle = 'password'
      }, 100)
    })
  },
  methods: {
    alyOnSubmit() {
      this.$refs.loginForm.validate(valid => {
        if (!valid) {
          return
        }
        this.$emit('login', this.loginForm)
      })
    },
    logInfo() {
      const loginName = localStorage.getItem('pskh_loginName')
      const loginPassword = localStorage.getItem('pskh_loginPassword')
      if (loginPassword) {
        this.loginForm.loginName = loginName
        this.loginForm.loginPassword = window.atob(loginPassword)
      }
    },
    togglePwdDisplay() {
      this.inputStyle = this.inputStyle === 'password' ? 'text' : 'password'
    },
  },
}
</script>
<style lang="scss" scoped>
.login-account-form {
  width: 100%;
  .perfix-icon {
    margin-left: 10px;
    color: #1b8aee;
  }
  .pwd-eye-view {
    cursor: pointer;
    display: inline-block;
    width: 50px;
    height: 100%;
    line-height: 42px;
  }
  i {
    font-size: 18px;
    line-height: 42px;
    color: #a8d2f7;
  }
  ::v-deep .el-input {
    width: 100%;
    height: 42px;
    background: #ffffff;
    border-radius: 4px;
    input {
      border-radius: 4px !important;
      height: 100%;
      padding-left: 50px;
      padding-right: 50px;
      border-color: #a8d2f7;
      &:focus {
        border-color: #1b8aee;
        box-shadow: 0px 3px 9px 1px rgba(113, 145, 181, 0.5);
      }
    }
    &.code-input input {
      border-top-right-radius: 0px !important;
      border-bottom-right-radius: 0px !important;
    }
    .el-input-group__append {
      color: #fff;
      background: linear-gradient(0deg, #0074f4 0%, #2099ff 100%);
      border-top-right-radius: 4px !important;
      border-bottom-right-radius: 4px !important;
    }
  }

  .options {
    display: flex;
    align-items: center;
    ::v-deep .remember {
      .el-checkbox {
        display: flex;
        align-items: center;
        .el-checkbox__label {
          color: #888;
          font-size: 16px;
        }
        .el-checkbox__input {
          margin-top: 4px;
        }
      }
      .is-checked {
        .el-checkbox__inner {
          background-color: #7db0fa;
          border-color: #7db0fa;
        }
        .el-checkbox__inner::after {
          border-width: 2px;
        }
      }
      .is-focus {
        .el-checkbox__inner {
          border-color: #7db0fa;
        }
      }
    }
    .forget {
      flex: 1;
      text-align: right;
      .el-button {
        color: #1960ab;
      }
    }
  }
  .login-btn {
    width: 100%;
    height: 42px;
    margin-top: 30px;
    background: linear-gradient(0deg, #0074f4 0%, #0060c4 100%);
    border-radius: 4px;
    font-size: 18px;
    line-height: 42px;
    font-weight: 600;
    text-align: center;
    color: #ffffff;
    cursor: pointer;
  }
}
</style>
